﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title id="Description">Column and Cells Alignment in jqxDataTable</title>
    <meta name="description" content="This sample demonstrates how we can Align Columns and Cells in jQWidgets DataTable.">
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdatatable.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var url = "../sampledata/orders.xml";
            // prepare the data
            var source =
            {
                datatype: "xml",
                datafields: [
                    { name: 'ShippedDate', map: 'm\\:properties>d\\:ShippedDate', type: 'date' },
                    { name: 'Freight', map: 'm\\:properties>d\\:Freight', type: 'float' },
                    { name: 'ShipName', map: 'm\\:properties>d\\:ShipName' },
                    { name: 'ShipAddress', map: 'm\\:properties>d\\:ShipAddress' },
                    { name: 'ShipCity', map: 'm\\:properties>d\\:ShipCity' },
                    { name: 'ShipCountry', map: 'm\\:properties>d\\:ShipCountry' }
                ],
                root: "entry",
                record: "content",
                id: 'm\\:properties>d\\:OrderID',
                url: url,
                pager: function (pagenum, pagesize, oldpagenum) {
                    // callback called when a page or page size is changed.
                }
            };
            var dataAdapter = new $.jqx.dataAdapter(source);

            $("#dataTable").jqxDataTable(
            {
                width: 850,
                source: dataAdapter,
                sortable: true,
                pageable: true,
                columnsResize: true,
                columns: [
                  { text: 'Shipped Date', datafield: 'ShippedDate', width: '50%', cellsFormat: 'D' },
                  { text: 'Freight', datafield: 'Freight', width: '50%', cellsFormat: 'F2' }
                ]
            });

            $("#columnAlignment").jqxDropDownList({selectedIndex: 0, autoDropDownHeight: true, source: ['Left', 'Center', 'Right'], height: 25 });
            $("#columnAlignment").on('change', function (event) {
                var index = event.args.index;
                switch (index) {
                    case 0:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'align', 'left');
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'align', 'left');
                        break;
                    case 1:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'align', 'center');
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'align', 'center');
                        break;
                    case 2:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'align', 'right');
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'align', 'right');
                        break;
                }
            });
            $("#cellsAlignment").jqxDropDownList({ selectedIndex: 0, autoDropDownHeight: true, source: ['Left', 'Center', 'Right'], height: 25 });
            $("#cellsAlignment").on('change', function (event) {
                var index = event.args.index;
                switch (index) {
                    case 0:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsAlign', 'left');
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsAlign', 'left');
                        break;
                    case 1:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsAlign', 'center');
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsAlign', 'center');
                        break;
                    case 2:
                        $("#dataTable").jqxDataTable('setColumnProperty', 'ShippedDate', 'cellsAlign', 'right');
                        $("#dataTable").jqxDataTable('setColumnProperty', 'Freight', 'cellsAlign', 'right');
                        break;
                }
            });
        });
    </script>
</head>
<body class='default'>
    <div id="dataTable">
    </div>
    <div style="font-size: 13px; font-family: Verdana; width: 600px; margin-top: 10px;">
        <div style="float: left; width: 300px;">
            <h4>Column Alignment</h4>
            <div id="columnAlignment"></div>
        </div>
        <div style="float: left; width: 300px;">
            <h4>Cells Alignment</h4>
            <div id="cellsAlignment"></div>
        </div>
    </div>
</body>
</html>
